var home =angular.module("home",['ngRoute']);
var time=0;
var time1=0;

home.config(function ($routeProvider) {
			 $routeProvider.when("/",{
            templateUrl:"Home.html"
        }).when("/xi",{
            templateUrl:"news.html"
        }).when("/cq/:id",{
            templateUrl:"huoguo.html"
        }).when("/ji",{
            templateUrl:"join.html"
        }).when("/sh/:id",{
            templateUrl:"food.html"
        }).when("/hu/:id",{
            templateUrl:"produce.html"
        }).when("/li",{
            templateUrl:"touchus.html"
        }).otherwise({
            templateUrl:"Home.html"
        });

    });
	

home.controller('homea',function($scope,$interval,$http){
	clearInterval(time);
	clearInterval(time1);
	var inhome =0;
		time=setInterval(function(){
			
			if(inhome ==3){
				inhome=0;
				$(".home-lun")[0].style.left=-$(".home-lun>img")[0].offsetWidth*inhome+"px";
			}
				inhome++;
			$(".home-lunul li").css("background","red");
			$(".home-lunul li").eq(inhome%3).css("background","white");
			
				var t=0;
				var b=$(".home-lun")[0].offsetLeft;
				var c=inhome*-$(".home-lun>img")[0].offsetWidth-b;
				var d=20;
				 time1=setInterval(function(){
					t++;
					if(t==d){
						clearInterval(time1);
					}
				$(".home-lun")[0].style.left=Tween.Linear(t,b,c,d)+"px";
				},20)
			
			
			
		},1000);
		$http.get("../php/home.php?hlogo=1").success(
			function(data){
				$scope.homeData=data;
			}
		)
		$http.get("../php/home.php?hlogo=2").success(
			function(data){
				$scope.foodData=data;
			}
		)
		
		
	
})



home.controller("produce",function($scope,$http,$routeParams){
	clearInterval(time);
	clearInterval(time1);
				$scope.prod=true;
			var dd = $routeParams.id;
			if(dd == "h"){
				$http.get("../php/produce.php?p=1").success(function(data){
				
				$scope.prodata=data;
			});
			
			}else{
				$scope.prod=false;
				$http.get("../php/produce.php?p=3&dd="+dd).success(function(data){
				$scope.img1 =data[0].img;
				$scope.name1 =data[0].name;
				$scope.content1 =data[0].content;
				$scope.addr1 =data[0].addr;
				$scope.Tel1 =data[0].Tel;
				
			});
				
			}
			
			$scope.proch=function(img,name,content,addr,Tel){
				$scope.prod=false;
				$scope.img1 =img;
				$scope.name1 =name;
				$scope.content1 =content;
				$scope.addr1 =addr;
				$scope.Tel1 =Tel;
				
			}
		$http.get("../php/produce.php?p=2").success(function(data){
				
				$scope.proda=data;
			})
		
			
			
	});
	

	home.controller("public",function($scope){
			$scope.fenlis=false;
			$(".public-D1:eq(0) span").css("color","red");
		$scope.fen=function(){
			$(".public-D1 span").css("color","black");
			
			$(".public-D1:eq(0) span").css("color","red");
			
			$scope.fenlis=!$scope.fenlis;
			$('.public-D1:eq(0) img')[0].src="../img/fen1.png";
			$('.public-D1:eq(1) img')[0].src="../img/shou.png";
			$('.public-D1:eq(2) img')[0].src="../img/jia.png";
		}
		$scope.dbt=function(){
			$scope.fenlis=!$scope.fenlis;
			
			
		}
		$scope.clear=function(n){
			$scope.fenlis=false;
			if(n==1){
				$(".public-D1 span").css("color","black");
			
			$(".public-D1:eq(1) span").css("color","red");
				$('.public-D1:eq(0) img')[0].src="../img/fen.png";
			$('.public-D1:eq(1) img')[0].src="../img/shou1.png";
			$('.public-D1:eq(2) img')[0].src="../img/jia.png";
			}
			else{
				
				$(".public-D1 span").css("color","black");
			
			$(".public-D1:eq(2) span").css("color","red");
				$('.public-D1:eq(0) img')[0].src="../img/fen.png";
			$('.public-D1:eq(1) img')[0].src="../img/shou.png";
			$('.public-D1:eq(2) img')[0].src="../img/jia1.png";
			}
			
		}
			
			
	});
	


	home.controller("food",function($scope,$http,$routeParams){
			clearInterval(time);
	clearInterval(time1);
			$scope.fodd=true;
		var s = $routeParams.id;
		if(s == "s"){
			$http.get("../php/food.php?f=1").success(function(data){
				
				$scope.foda =data;
			})
		}else{
			$http.get("../php/food.php?f=4&s="+s).success(function(data){
				$scope.fodd=false;
				$scope.fimg=data[0].img;	
				$scope.fname=data[0].name;
				$scope.fprice=data[0].price;
				$scope.fcontent=data[0].content;
				$scope.ftxt1=data[0].txt1;
				$scope.sname =data[0].sname;
				$scope.faddr =data[0].addr;
				$scope.fTel =data[0].Tel;
			})
			
		}
		
		
			
			
			$scope.fch=function(fimg,fname,fprice,fcontent,ftxt1,sname,addr,Tel){
				$scope.fodd=false;
				$scope.fimg=fimg;	
				$scope.fname=fname;
				$scope.fprice=fprice;
				$scope.fcontent=fcontent;
				$scope.ftxt1=ftxt1;
				$scope.sname =sname;
				$scope.faddr =addr;
				$scope.fTel =Tel;
			}
			
			
			$scope.fchang=function(f,t){
				$(".foodDTopDTopD").css({
					color:"black",
					borderBottom:"0px solid red"
				});
				
				$(".foodDTopDTopD").eq(t).css({
					color:"red",
					borderBottom:"1px solid red"
				})
				$http.get("../php/food.php?f=2&ft="+f).success(function(data){
				
				
				$scope.foda =data;
			})
				
			}
			
			
			$scope.sou =function(){
				$scope.fodd=false;
				var fval =$(".foodDTopIn").eq(0).val();
				
			$http.get("../php/food.php?f=3&fval="+fval).success(function(data){
				
			
				$scope.fimg=data[0].img;	
				$scope.fname=data[0].name;
				$scope.fprice=data[0].price;
				$scope.fcontent=data[0].content;
				$scope.ftxt1=data[0].txt1;
				$scope.sname =data[0].sname;
				$scope.faddr =data[0].addr;
				$scope.fTel =data[0].Tel;
				
				
				
			})
			
			}
			
			
	});
	
//重庆火锅
home.controller("chong",function($scope,$http,$routeParams){
	clearInterval(time);
	clearInterval(time1);
		var c =$routeParams.id;
			
			if(c=="c"){
				$scope.chshow=true;
			$scope.chchang =true;
			
			
			$http.get("../php/huoguo.php?huo=1&ht=A").success(function(data){
				
				$scope.hda1=data;
			})
			
			$http.get("../php/huoguo.php?huo=1&ht=B").success(function(data){
				$scope.hda2=data;
			})
				
			}else{
			 	$scope.chshow=false;
			 	$http.get("../php/huoguo.php?huo=4&c="+c).success(function(data){
			$scope.hname =data[0].name;
			$scope.himg =data[0].img;
			$scope.haddr =data[0].addr;
			$scope.hTel =data[0].Tel;
			$scope.hcontent =data[0].content;
			$scope.htxt1 =data[0].text1;
			
			})
				
				
			}
			
			
			
			$scope.hdian=function(hname,himg,haddr,hTel,hcontent,htxt1){
				$scope.chshow=false;
			$scope.hname =hname;
			$scope.himg =himg;
			$scope.haddr =haddr;
			$scope.hTel =hTel;
			$scope.hcontent =hcontent;
			$scope.htxt1 =htxt1;
			
			
			}
			
			
			$scope.chD =function(){
				var hval =$(".chDTopIn").val();
				
				
				
				$http.get("../php/huoguo.php?huo=2&hval="+hval).success(function(data){
					
					
			var st ="QWERTYUIOPASDFGHJKLZXCVBNM";
			var re =new RegExp( hval ,"i");
		
			if(!re.test(st)){
				
				if(data.length==0){
					
					$(".chDTopIn").val("请输入店名");
				}else if(data.length==1){
					
			$scope.chshow=false;
			$scope.hname =data[0].name;
			$scope.himg =data[0].img;
			$scope.haddr =data[0].addr;
			$scope.hTel =data[0].Tel;
			$scope.hcontent =data[0].content;
			$scope.htxt1 =data[0].text1;	
				}
				
			}else{
				
				if(data.length==0){
					$(".chDTopIn").val("请输入店名");
				}else{
					
					$scope.chchang =false;
					$scope.hda3=data;
				}
				
			}
					
			
			})
			
				
			}
			
			
			$scope.xuan=function(n){
				$scope.chchang =false;
				$scope.htb =n;
				$http.get("../php/huoguo.php?huo=3&hb="+n).success(function(data){
				$scope.hda3=data;
			})
			}
			
			
		})



















home.controller('newsa',function($scope,$http){
	clearInterval(time);
	clearInterval(time1);
	$http.get("../php/news.php?hlogo=1").success(
			function(data){
				$scope.newData=data;
			}
		)
	$scope.bbb=function(na,tim,cot,imgb,contb){
		$('.new-news').css('display','none');
		$('.new-xiangqing').css('display','block');
			$scope.imgb = imgb;
			$scope.na = na;
			$scope.cot = cot;
			$scope.contb =contb;
			$scope.tim = tim;
	}
})








//chain部分的angular
home.controller('chainCtrl', function($scope){
	clearInterval(time);
	clearInterval(time1);
	//上传图片
		$(document).ready(function () {
				$("#chain-pt").change(function () {
					var fil = this.files;
					for (var i = 0; i < fil.length; i++) {
							reads(fil[i]);
					}
				});
		});
		
		
		function reads(fil){
				var reader = new FileReader();
				reader.readAsDataURL(fil);
				reader.onload = function()
				{
				document.getElementById("chain-ddd").innerHTML += "<img src='"+reader.result+"'>";
				};
		}
	
	//验证
	$scope.chain1=function(){
		
		var cput1=$scope.chaininput1;
		console.log(cput1)
		if (cput1=="") {
			console.log(00000)
				$scope.chains1="请输入内容";
		}else{
			$scope.chains1="";
		};	
	}
	$scope.chain2=function(){
		var cput2=$scope.chaininput2;
		 if (cput2=="") {
		 	console.log(222);
				$scope.chains2="请输入联系人";
		}else{
			$scope.chains2="";
		};  	
	};
	$scope.chain3=function(){
			var cput3=$scope.chaininput3;
			var cReg=/^1(3|4|5|7|8)\d{9}$/;
		if (cput3=="") {
				$scope.chains3="请输入联系方式";
		}else if(!cReg.test(cput3)){
			   $scope.chains3="方式无效";
		}else if(cReg.test(cput3)){
			   $scope.chains3=""
		}			
	};
	$scope.chain4=function(){
		var cput4=$scope.chaininput4;
		if (cput4=="") {
				$scope.chains4="请输入联系人";
		}else{
			$scope.chains4="";
		};	
	};
	



$(function() {
			$("#chain-pt").change(function() {
			var $file = $(this);
			var fileObj = $file[0];
			var windowURL = window.URL || window.webkitURL;
			var dataURL;
			var $img = $("#preview");
			 
			if(fileObj && fileObj.files && fileObj.files[0]){
					dataURL = windowURL.createObjectURL(fileObj.files[0]);
					$img.attr('src',dataURL);
			}else{
					dataURL = $file.val();
					var imgObj = document.getElementById("preview");
					imgObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
					imgObj.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = dataURL;
					
		
		}
		
				
			 
			}
			);
		});

});




	home.controller('validateCtrl', function($scope) {
	clearInterval(time);
	clearInterval(time1);
					//	textarea验证非空
			   		$(".join-textarea").bind("input propertychange",function(){
							if ($(this).val()==false) {
									$(".join-li3-p").css("opacity",1)
								}else{
									$(".join-li3-p").css("opacity",0)
								}
					});
		
					//联系方式验证 
					var myreg1=/^1(3|4|5|7|8)\d{9}$/;
					$scope.joinFun=function(){
						var num = $scope.num;
						if (num==undefined) {
							$scope.jointel="请输入手机号";
						} else  if(!myreg1.test(num)){
							$scope.jointel="无效号码";
						}else if(myreg1.test(num)){
							$scope.jointel="";
						}					
					}

	
	
$(".join-li2").click(function(){
	console.log("111");
	$(this).css({color:"red",borderColor:"red"});
	$(".join-li1").css({color:"black",borderColor:"transparent"});	
	$(".join-li3").css({color:"black",borderColor:"transparent"});	
	$(".join-page1").css("display","none");
	$(".join-page3").css("display","none");
	$(".join-page2").css("display","block");
});
$(".join-li3").click(function(){
	$(this).css({color:"red",borderColor:"red"});
	$(".join-li1").css({color:"black",borderColor:"transparent"});	
	$(".join-li2").css({color:"black",borderColor:"transparent"});	
	$(".join-page1").css("display","none");
	$(".join-page2").css("display","none");
	$(".join-page3").css("display","block");
});
$(".join-li1").click(function(){
	$(this).css({color:"red",borderColor:"red"});
	$(".join-li2").css({color:"black",borderColor:"transparent"});	
	$(".join-li3").css({color:"black",borderColor:"transparent"});	
	$(".join-page2").css("display","none");
	$(".join-page3").css("display","none");
	$(".join-page1").css("display","block");
});

	
	
	
})
